package com.credit.anypermission.permission

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.XXPermissions

class XXPermission : PermissionBase() {

    private lateinit var xxPermissions: XXPermissions


    override fun setActivity(activity: FragmentActivity) {
        super.setActivity(activity)
        xxPermissions = XXPermissions.with(activity)
    }

    override fun setFragment(fragment: Fragment) {
        super.setFragment(fragment)
        xxPermissions = XXPermissions.with(fragment)
    }

    override fun request() {
        xxPermissions.permission(mUnGrantedPermissions.peek()!!).request(object : OnPermissionCallback {
            override fun onGranted(permissions: MutableList<String>, allGranted: Boolean) {
                mUnGrantedPermissions.poll()
                next()
            }

            override fun onDenied(permissions: MutableList<String>, doNotAskAgain: Boolean) {
                again()
            }
        })
    }


}